setTimeout(function(){ 
	//$("#appName").focus();
	$("#appName").rules("add",{
		remote: {
			url: 'qz/apps/checkName',
			type: "get",
			data: {"id":""},
			dataType: "JSON", 
			dataFilter:function(data,type){						 
				return data=="false"?false:true;
			}
		}, 		
		messages: {remote: "该应用名称已存在"}
	});
} , parseInt(Math.random() * 1000));


setTimeout(function(){ 
	$("#code").rules("add",{
		remote: {
			url: 'qz/apps/checkCode',
			type: "get",
			data: {"id":""},
			dataType: "JSON", 
			dataFilter:function(data,type){	
				return data=="false"?false:true;
			}
		}, 		
		messages: {remote: "该应用编码已存在"}
	}); 
} , parseInt(Math.random() * 1000));

var app = angular.module('qzApp', []);


app.controller('qzAppController', function($scope, $http) {
	$scope.qzApp;
	$scope.view=function(){
		$http.get(timestamp('qz/channel/getAll/')).success(function(response){
			$scope.channelList=response.data;
		 
			$("#channelId").select2({
				 placeholder: "请选择机构",
				 allowClear: true
			});
	    });
			
		$http.get(timestamp('qz/business/getAll/')).success(function(response){
			$scope.businessList=response.data;
		 
			$("#businessId").select2({
				 placeholder: "请选择业务分类",
				 allowClear: true
			});
	    });
		
		$http.get(timestamp('sys/dic/getByGroup/yylx')).success(function(response){
			$scope.typeList=response.data;
		 
			$("#type").select2({
				 placeholder: "请选择应用类型,必选项",
				 allowClear: true
			});
			$("#type").change(function(){  
				$(this).valid();
			}); 
	    });	
		$scope.qzApp={};
	}
	
	$scope.view();
	
	$scope.appSave=function(){
	   if($("#myForm").valid()){
		   $http.post('qz/apps/add/', $scope.qzApp).success(function(response){	
               //window.location.href = "manage/apps/edit.jsp?id="+response.data; 
               redirectUrl("manage/apps/","edit.jsp?id="+response.data);
           });
	   }
	}
	
	$scope.refreshData=function(){
		$scope.view();
	}
	
	$scope.appReset=function(){		
		$scope.view();
	}
	
	$scope.appCancle=function(){
		redirectUrl("manage/apps/","list.jsp");
	}
});